/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on Sep 7, 2011, 12:45:49 AM
 */
package Views;

import Controllers.AccountController;
import Models.Account;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Pan
 */
public class NewJFrame2 extends javax.swing.JFrame {
    
    ArrayList<Account> accountList = new ArrayList<Account>();

    /** Creates new form NewJFrame */
    public NewJFrame2() {
        initComponents();
        
        accountList = AccountController.GetAccounts();
        LoadAccountData(accountList);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        btn_FilterAccount = new javax.swing.JButton();
        btn_ResetAccount = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtAccSerialNo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cbxOfficerRole = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtOfficerFullName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtOfficerAddress = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtOfficerPhone = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cbxOfficerGender = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        spnMinOfficerDOB = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        spnMaxOfficerDOB = new javax.swing.JSpinner();
        jPanel6 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        txtOfficerRank = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtDepartment = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtRegion = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        cbxIsRetired = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbl_Accounts = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        btn_AddAccount = new javax.swing.JButton();
        btn_EditAccount = new javax.swing.JButton();
        btn_DetailedAccount = new javax.swing.JButton();
        btn_RefreshAccount = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setDividerLocation(200);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        btn_FilterAccount.setText("Filter");
        btn_FilterAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_FilterAccountActionPerformed(evt);
            }
        });

        btn_ResetAccount.setText("Reset");
        btn_ResetAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ResetAccountActionPerformed(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Account Info"));

        jLabel1.setText("Serial No:");

        jLabel2.setText("Access Permission:");

        cbxOfficerRole.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Both", "Officer", "Director" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAccSerialNo, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxOfficerRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtAccSerialNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cbxOfficerRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Personal Info"));

        jLabel3.setText("Name:");

        jLabel4.setText("Address:");

        jLabel5.setText("Phone No:");

        jLabel6.setText("Gender:");

        cbxOfficerGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Both", "Male", "Female" }));

        jLabel7.setText("Date of Birth (mm/dd/yyyy):");

        jLabel8.setText("From:");

        spnMinOfficerDOB.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(-946796400000L), new java.util.Date(-946796400000L), new java.util.Date(), java.util.Calendar.DAY_OF_MONTH));
        spnMinOfficerDOB.setEditor(new javax.swing.JSpinner.DateEditor(spnMinOfficerDOB, "MM/dd/yyyy"));

        jLabel9.setText("To:");

        spnMaxOfficerDOB.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), new java.util.Date(-946796400000L), new java.util.Date(), java.util.Calendar.DAY_OF_MONTH));
        spnMaxOfficerDOB.setEditor(new javax.swing.JSpinner.DateEditor(spnMaxOfficerDOB, "MM/dd/yyyy"));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxOfficerGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtOfficerFullName, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtOfficerAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtOfficerPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(48, 48, 48)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(spnMaxOfficerDOB, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(spnMinOfficerDOB, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel7))))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtOfficerFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtOfficerAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtOfficerPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(cbxOfficerGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(spnMinOfficerDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(spnMaxOfficerDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Service Info"));

        jLabel10.setText("Rank:");

        jLabel11.setText("Current Department:");

        jLabel12.setText("Region of Service:");

        jLabel13.setText("Service Status:");

        cbxIsRetired.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Both", "Retired or out of duty", "In active duty" }));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbxIsRetired, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel6Layout.createSequentialGroup()
                            .addComponent(jLabel12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtRegion))
                        .addGroup(jPanel6Layout.createSequentialGroup()
                            .addComponent(jLabel10)
                            .addGap(18, 18, 18)
                            .addComponent(txtOfficerRank))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel6Layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtOfficerRank, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtRegion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(cbxIsRetired, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_FilterAccount)
                        .addGap(18, 18, 18)
                        .addComponent(btn_ResetAccount)))
                .addGap(6, 6, 6)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btn_FilterAccount)
                            .addComponent(btn_ResetAccount))))
                .addContainerGap())
        );

        jSplitPane1.setTopComponent(jPanel1);

        tbl_Accounts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Account ID", "Officer's Name", "Badge Serial No.", "Officer's Gender", "Rank", "Access Permission", "Retired From Duty?"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbl_Accounts);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Control Panel"));

        btn_AddAccount.setText("New Recruitment");
        btn_AddAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AddAccountActionPerformed(evt);
            }
        });

        btn_EditAccount.setText("Update Selected Account");
        btn_EditAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_EditAccountActionPerformed(evt);
            }
        });

        btn_DetailedAccount.setText("View Detailed Account");
        btn_DetailedAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_DetailedAccountActionPerformed(evt);
            }
        });

        btn_RefreshAccount.setText("Refresh");
        btn_RefreshAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_RefreshAccountActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btn_EditAccount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_DetailedAccount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_AddAccount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_RefreshAccount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(btn_AddAccount)
                .addGap(18, 18, 18)
                .addComponent(btn_EditAccount)
                .addGap(18, 18, 18)
                .addComponent(btn_DetailedAccount)
                .addGap(18, 18, 18)
                .addComponent(btn_RefreshAccount)
                .addContainerGap(81, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btn_RefreshAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_RefreshAccountActionPerformed
    accountList = AccountController.GetAccounts();
    LoadAccountData(accountList);
}//GEN-LAST:event_btn_RefreshAccountActionPerformed
    
private void btn_DetailedAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_DetailedAccountActionPerformed
    if (tbl_Accounts.getSelectedRowCount() < 1) {
        JOptionPane.showMessageDialog(null, "No Account selected!", "Error Message", JOptionPane.WARNING_MESSAGE);
    } else {
        int _ID = Integer.parseInt(tbl_Accounts.getModel().getValueAt(tbl_Accounts.getSelectedRow(), 0).toString());
        DetailedAccount detailCriminal = new DetailedAccount(null, true, AccountController.GetAccountByID(_ID));
        detailCriminal.setVisible(true);
    }
}//GEN-LAST:event_btn_DetailedAccountActionPerformed
    
private void btn_AddAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AddAccountActionPerformed
    AddAccount addAccount = new AddAccount(null, true);
    addAccount.addWindowListener(new WindowListener() {
        
        @Override
        public void windowOpened(WindowEvent e) {
        }
        
        @Override
        public void windowClosing(WindowEvent e) {
        }
        
        @Override
        public void windowClosed(WindowEvent e) {
            btn_RefreshAccount.doClick();
        }
        
        @Override
        public void windowIconified(WindowEvent e) {
        }
        
        @Override
        public void windowDeiconified(WindowEvent e) {
        }
        
        @Override
        public void windowActivated(WindowEvent e) {
        }
        
        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });
    addAccount.setVisible(true);
}//GEN-LAST:event_btn_AddAccountActionPerformed
    
private void btn_EditAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_EditAccountActionPerformed
    if (tbl_Accounts.getSelectedRowCount() < 1) {
        JOptionPane.showMessageDialog(null, "No Account selected!", "Error Message", JOptionPane.WARNING_MESSAGE);
    } else {
        int _ID = Integer.parseInt(tbl_Accounts.getModel().getValueAt(tbl_Accounts.getSelectedRow(), 0).toString());
        EditAccount editAccount = new EditAccount(null, true, AccountController.GetAccountByID(_ID));
        editAccount.addWindowListener(new WindowListener() {
            
            @Override
            public void windowOpened(WindowEvent e) {
            }
            
            @Override
            public void windowClosing(WindowEvent e) {
            }
            
            @Override
            public void windowClosed(WindowEvent e) {
                btn_RefreshAccount.doClick();
            }
            
            @Override
            public void windowIconified(WindowEvent e) {
            }
            
            @Override
            public void windowDeiconified(WindowEvent e) {
            }
            
            @Override
            public void windowActivated(WindowEvent e) {
            }
            
            @Override
            public void windowDeactivated(WindowEvent e) {
            }
        });
        editAccount.setVisible(true);
    }
}//GEN-LAST:event_btn_EditAccountActionPerformed
    
private void btn_ResetAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ResetAccountActionPerformed
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    
    txtAccSerialNo.setText("");
    cbxOfficerRole.setSelectedIndex(0);
    txtOfficerFullName.setText("");
    txtOfficerAddress.setText("");
    txtOfficerPhone.setText("");
    cbxOfficerGender.setSelectedIndex(0);
    Calendar cal = Calendar.getInstance();
    try {
        spnMinOfficerDOB.setValue(formatter.parse("01/01/1940"));
        spnMaxOfficerDOB.setValue(cal.getTime());
    } catch (ParseException ex) {
        Logger.getLogger(NewJFrame2.class.getName()).log(Level.SEVERE, null, ex);
    }
    txtOfficerRank.setText("");
    txtDepartment.setText("");
    txtRegion.setText("");
    cbxIsRetired.setSelectedIndex(0);
    
    btn_RefreshAccount.doClick();
}//GEN-LAST:event_btn_ResetAccountActionPerformed
    
private void btn_FilterAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_FilterAccountActionPerformed
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    ArrayList<Account> resultList = new ArrayList<Account>();
    
    HashMap parametersMap = new HashMap();
    parametersMap.put("AccSerialNo", txtAccSerialNo.getText());
    parametersMap.put("OfficerFullName", txtOfficerFullName.getText());
    String _officerGender = "";
    if (cbxOfficerGender.getSelectedIndex() == 1) {
        _officerGender = "1";
    } else if (cbxOfficerGender.getSelectedIndex() == 2) {
        _officerGender = "0";
    }
    parametersMap.put("OfficerGender", _officerGender);
    parametersMap.put("OfficerRank", txtOfficerRank.getText());
    String _officerRole = "";
    if (cbxOfficerRole.getSelectedIndex() != 0) {
        _officerRole = cbxOfficerRole.getSelectedItem().toString();
    }
    parametersMap.put("OfficerRole", _officerRole);
    parametersMap.put("Department", txtDepartment.getText());
    parametersMap.put("Region", txtRegion.getText());
    parametersMap.put("OfficerAddress", txtOfficerAddress.getText());
    Date _minDOB = null;
    Date _maxDOB = null;
    try {
        String dateString = formatter.format(spnMinOfficerDOB.getValue());
        _minDOB = formatter.parse(dateString);
        dateString = formatter.format(spnMaxOfficerDOB.getValue());
        _maxDOB = formatter.parse(dateString);
    } catch (ParseException ex) {
        Logger.getLogger(NewJFrame2.class.getName()).log(Level.SEVERE, null, ex);
    }
    parametersMap.put("MinOfficerDOB", _minDOB);
    parametersMap.put("MaxOfficerDOB", _maxDOB);
    parametersMap.put("OfficerPhone", txtOfficerPhone.getText());
    String _isRetired = "";
    if (cbxIsRetired.getSelectedIndex() == 1) {
        _isRetired = "1";
    } else if (cbxIsRetired.getSelectedIndex() == 2) {
        _isRetired = "0";
    }
    parametersMap.put("IsRetired", _isRetired);
    
    resultList = AccountController.FilterAccount(parametersMap);
    LoadAccountData(resultList);
}//GEN-LAST:event_btn_FilterAccountActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            public void run() {
                new NewJFrame2().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_AddAccount;
    private javax.swing.JButton btn_DetailedAccount;
    private javax.swing.JButton btn_EditAccount;
    private javax.swing.JButton btn_FilterAccount;
    private javax.swing.JButton btn_RefreshAccount;
    private javax.swing.JButton btn_ResetAccount;
    private javax.swing.JComboBox cbxIsRetired;
    private javax.swing.JComboBox cbxOfficerGender;
    private javax.swing.JComboBox cbxOfficerRole;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSpinner spnMaxOfficerDOB;
    private javax.swing.JSpinner spnMinOfficerDOB;
    private javax.swing.JTable tbl_Accounts;
    private javax.swing.JTextField txtAccSerialNo;
    private javax.swing.JTextField txtDepartment;
    private javax.swing.JTextField txtOfficerAddress;
    private javax.swing.JTextField txtOfficerFullName;
    private javax.swing.JTextField txtOfficerPhone;
    private javax.swing.JTextField txtOfficerRank;
    private javax.swing.JTextField txtRegion;
    // End of variables declaration//GEN-END:variables

    private void LoadAccountData(ArrayList<Account> listToLoad) {
        DefaultTableModel dtm = (DefaultTableModel) tbl_Accounts.getModel();
        while (dtm.getRowCount() > 0) {
            dtm.removeRow(0);
        }
        Vector row;
        if (listToLoad != null) {
            for (int i = 0; i < listToLoad.size(); i++) {
                Account _account = listToLoad.get(i);
                row = new Vector();
                row.addElement(_account.getID());
                row.addElement(_account.getFullName());
                row.addElement(_account.getSerialNo());
                if (_account.isGender()) {
                    row.addElement("Male");
                } else {
                    row.addElement("Female");
                }
                row.addElement(_account.getRank());
                row.addElement(_account.getRole());
                row.addElement(_account.isRetired());
                dtm.addRow(row);
            }
        }
    }
}
